<?php

namespace App\Models;

use App\Http\Middleware\Authenticate;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;
use Spatie\Permission\Traits\HasRoles;
use Tymon\JWTAuth\Contracts\JWTSubject;
class SystemAdmin extends Authenticatable implements JWTSubject
{
    use HasFactory;
    use PimpableTrait;
    use HasRoles;
    use SoftDeletes;
    protected $guard_name = 'admin';
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }
    /**
     * 可搜索字段
     */
    public $searchable = [
        'account',
        'last_ip',
        'last_time',
        'level',
        'status',
        'login_count',
        'roles',
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'merchant_id',
        'password',
        'account',
        'password',
        'avatar',
        'real_name',
        'roles',
        'level',
        'last_time',
        'login_count',

    ];

    /**
     * 可排序字段
     */
    public $sortable = [
        'roles',
        'last_time',
        'level',
        'login_count',
        'status',
        'is_del',
        'id',
    ];
    /**
     * 可进行模糊查询的字段
     */
    public $searchableModels = [
        'account' => '%field%',
        'real_name' => '%field%',
    ];

    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 管理员的所有操作记录
     */
    public function systemLog()
    {
        return $this->hasMany(SystemLog::class, 'admin_id', 'id');
    }

    /**
     * 管理员管理的所有文章
     */
    public function article()
    {
        return $this->hasMany(Article::class, 'admin_id', 'id');
    }

    /**
     * 管理员管理的所有文章
     */
    public function systemNoticeAdmin()
    {
        return $this->hasMany(SystemNoticeAdmin::class, 'admin_id', 'id');
    }

}
